/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 **************************************************************************
 * MIFSS  - content storage system
 * 
 *
 * @uthors: uros.kristan@gmail.com (Uroš Kristan ) Urosk.NET
 *         jernej.svigelj@gmail.com (Jernej Švigelj) 
 */
package net.monare.mifss.services;

import net.monare.mifss.configurations.pojo.ContentMetaDataDef;
import net.monare.mifss.exceptions.ContentManagerException;
import net.monare.mifss.exceptions.ContentServiceException;
import net.monare.mifss.exceptions.StorageManagerException;
import net.monare.mifss.exceptions.StorageServiceException;
import net.monare.mifss.lib.StorageProgressWalker;
import net.monare.mifss.managers.ContentManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.util.List;

@Service
public class ContentService {

    @Autowired
    private ContentManager contentManager;

    /**
     * Retrieves file from storage with given id verifyContent=true when
     * verifying file with defined storage hash method
     *
     * @param outFile
     * @param uuid
     * @param storageName
     * @param verifyContent
     * @throws ContentServiceException
     */
    @Transactional
    public void retriveContent(File outFile, String uuid, String storageName, boolean verifyContent) throws ContentServiceException {

        try {
            contentManager.retriveContent(outFile, uuid, storageName, verifyContent);
        } catch (ContentManagerException e) {
            throw new ContentServiceException(e);
        }
    }

    /**
     * Retrive complete list with rendition storages from given uuid
     *
     * @param uuid
     * @return
     * @throws ContentServiceException
     */
    @Transactional
    public List<ContentMetaDataDef> retriveContentMetaData(String uuid) throws ContentServiceException {

        try {
            return contentManager.retriveContentMetaData(uuid);
        } catch (ContentManagerException e) {
            throw new ContentServiceException(e);
        }
    }

    @Transactional
    public ContentMetaDataDef retriveContentMetaData(String uuid, String storageName) throws ContentServiceException {

        try {
            return contentManager.retriveContentMetaData(uuid, storageName);
        } catch (ContentManagerException e) {
            throw new ContentServiceException(e);
        }
    }

    @Transactional
    public ContentMetaDataDef writeContent(String fileName, File file, String storageName) throws ContentServiceException {

        try {
            return contentManager.writeContent(fileName, file, storageName);
        } catch (ContentManagerException e) {
            throw new ContentServiceException(e);
        }

    }



}
